<div class="form__wrapper">
  <div class="card" data-controller="accordion" id="accordion-title">
    <div class="card-divider">
      <button class="card-divider-button" data-open="true" data-controls="panel-title" type="button">
        <%= icon "arrow-right-s-line" %>
        <h2 class="card-title" id="title">
          <%= t("title", scope: "decidim.initiatives.admin.initiatives.form") %>
        </h2>
      </button>
    </div>

    <div id="panel-title" class="card-section">
      <div class="row column">
        <%= form.translated :text_field, :title, autofocus: true, disabled: !allowed_to?(:update, :initiative, initiative: current_initiative), aria: { label: :title } %>
      </div>

      <div class="row column">
        <%= form.translated :editor, :description, lines: 8, disabled: !allowed_to?(:update, :initiative, initiative: current_initiative), aria: { label: :description } %>
      </div>
    </div>
  </div>

  <div class="card" data-controller="accordion" id="accordion-settings">
    <div class="card-divider">
      <button class="card-divider-button" data-open="true" data-controls="panel-settings" type="button">
        <%= icon "arrow-right-s-line" %>
        <h2 class="card-title" id="settings">
          <%= t("settings", scope: "decidim.initiatives.admin.initiatives.form") %>
        </h2>
      </button>
    </div>

    <div id="panel-settings" class="card-section">
      <div class="row">
        <div class="columns">
          <%= form.select :state,
                          Decidim::Initiative.states.keys.map { |state| [I18n.t(state, scope: "decidim.initiatives.admin_states"), state] },
                          {},
                          { disabled: !@form.state_updatable? } %>
        </div>
      </div>

      <div class="row">
        <% unless single_initiative_type? %>
        <div class="columns">
          <%= form.select :type_id,
                          initiative_type_options,
                          {},
                          {
                            disabled: !@form.signature_type_updatable?,
                            "data-scope-selector": "initiative_decidim_scope_id",
                            "data-scope-id": form.object.decidim_scope_id.to_s,
                            "data-scope-search-url": decidim_initiatives.initiative_type_scopes_search_url(locale: I18n.locale),
                            "data-signature-types-selector": "initiative_signature_type",
                            "data-signature-type": current_initiative.signature_type,
                            "data-signature-types-search-url": decidim_initiatives.initiative_type_signature_types_search_url(locale: I18n.locale)
                          } %>
        </div>
        <% end %>
        <div class="columns">
          <%= form.select :decidim_scope_id, [], {}, { disabled: !@form.signature_type_updatable? } %>
        </div>
      </div>

      <% if current_initiative.published? && current_user.admin? %>
        <div class="row">
          <div class="columns">
            <%= form.date_field :signature_start_date %>
          </div>

          <div class="columns">
            <%= form.date_field :signature_end_date %>
          </div>
        </div>
      <% end %>

      <% if can_edit_custom_signature_end_date?(current_initiative) %>
        <div class="row column">
          <%= form.date_field :signature_end_date, disabled: !allowed_to?(:update, :initiative, initiative: current_initiative) %>
        </div>
      <% end %>

      <% if current_initiative.area_enabled? %>
        <div class="row column">
          <%= form.areas_select :area_id,
                                areas_for_select(current_organization),
                                {
                                  selected: current_initiative.decidim_area_id,
                                  include_blank: current_initiative.decidim_area_id.blank? || current_initiative.created?
                                },
                                disabled: !@form.area_updatable? %>
        </div>
      <% end %>

      <div class="row">
        <div class="columns">
          <%= form.select :signature_type, [], {}, { disabled: !@form.signature_type_updatable? } %>
        </div>
      </div>

      <% if current_initiative.accepts_offline_votes? && current_user.admin? %>
        <div class="row">
          <div class="columns">
            <% @form.offline_votes.each do |scope_id, (votes, scope_name)| %>
              <%= label_tag "initiative_offline_votes_#{scope_id}", t("activemodel.attributes.initiative.offline_votes_for_scope", scope_name: translated_attribute(scope_name)) %>
              <%= number_field_tag "initiative[offline_votes][#{scope_id}]", votes, min: 0, id: "initiative_offline_votes_#{scope_id}" %>
            <% end %>
          </div>
        </div>
      <% end %>
    </div>
  </div>
  <div class="card" data-controller="accordion" id="accordion-homepage_attachments">
    <div class="card-divider">
      <button class="card-divider-button" data-open="true" data-controls="panel-homepage_attachments" type="button">
        <%= icon "arrow-right-s-line" %>
        <h2 class="card-title" id="homepage_attachments">
          <%= t(".attachments_title") %>
        </h2>
      </button>
    </div>

    <div id="panel-homepage_attachments" class="card-section">
      <div class="row">
        <% if allowed_to?(:read, :attachment, initiative: current_participatory_space) %>
          <%= render partial: "initiative_attachments", locals: { current_initiative:, current_participatory_space: } %>
        <% end %>
      </div>
    </div>
  </div>
</div>
<%= append_javascript_pack_tag "decidim_initiatives_admin" %>
